#ifndef _HEADER_VegetableGarden_H
#include "VegetableGarden.h"
#endif



void VegetableGarden::setType(GardenTypeEnum type)
{
    this->gardenType = type;
}

/**
 * 跟据湿度传感器+菜地类型 共同判定是否应该灌溉
 * 
 * */
bool VegetableGarden::isCanWatering()
{
    //得到当前菜地湿度
    int value = humiditySensor.getValue();
    bool ret = false;

    switch (this->gardenType)
    {
    case Cabbage:
        if(value <= 60) ret = true;
        break;
    case Radish:
        if(value <= 20) ret = true;
        break;
    default:
        break;
    };
    this->canWatering = ret;
    return ret;
}

/**
 * 菜地初始化：菜地类型、菜地水路开关、菜地湿度探头
 * */
void VegetableGarden::init(VegetableGardenConfig* config)
{
    gardenType = config->gardenType;
    humiditySensor.setPort(config->humiditySensorPort);
    waterSwitch.setPort(config->waterSwitchPort);
}

void VegetableGarden::openWaterSwitch()
{
    this->waterSwitch.open();
}
void VegetableGarden::closeWaterSwitch()
{
    this->waterSwitch.close();
}

void VegetableGarden::toString(char* inStr)
{
    char temp1[100],temp2[100];
    this->humiditySensor.toString(temp1);
    this->waterSwitch.toString(temp2);
    sprintf(inStr,"VegetableGarden:{gardenType=%d,%s,%s}",this->gardenType,temp1,temp2);
}